package org.wendu.wdoa.security.user.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wendu.wdoa.common.page.PageParam;
import org.wendu.wdoa.common.page.PageUtils;
import org.wendu.wdoa.security.user.dao.UserDao;
import org.wendu.wdoa.security.user.dto.UserQueryDto;
import org.wendu.wdoa.security.user.dto.roleDto;
import org.wendu.wdoa.security.user.service.UserService;

import java.util.List;
import java.util.Map;
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    @Override
    public Map<String, Object> getUserList(PageParam pageParam) {
        return PageUtils.getPage(pageParam,()->userDao.findUserList(pageParam));
    }

    @Override
    public List<roleDto> getUserFunList() {
        return userDao.findUserFun();
    }

    @Override
    public List<Integer>  getUserFunIds(String u_id) {
        return userDao.findUserFunIds(u_id);
    }

    @Override
    public void confirmUserFuns(String u_id, Integer[] ro_ids) {
        userDao.deleteUserFuns(u_id); // 删除指定角色的所有权限
        if (ro_ids == null || ro_ids.length == 0) {
            return;
        }
        userDao.insertUserFuns(u_id, ro_ids);
    }


}
